import time
from public.action import *
from public.business import *
from public.testData import *
from public.tools import *

testcase = "dbshop013-分类编辑"

firefox = openBrowser(urlAdmin)
DBshopLoginAdmin(firefox)

# 1.点击添加分类按钮，
firefox.find_element_by_xpath('//i[@class="icon-th-list icon-white"]').click()
firefox.find_element_by_xpath('//a[contains(text(),"添加分类")]').click()
time.sleep(10)
# 分类名称“商品分类测试”
firefox.find_element_by_id("class_name").send_keys(goodsClassName)
# 分类排序输入1。
firefox.find_element_by_id("class_sort").clear()
firefox.find_element_by_id("class_sort").send_keys(1)
# 2.点击“保存分类”按钮”。
firefox.find_element_by_xpath('//button[contains(text(),"保存分类")]').click()
# 3.点击“商品分类测试”后方的分类编辑链接,进入商品分类编辑页面
# firefox.find_element_by_xpath('//td[contains(text(),"%s")]/following-sibling::td[2]'%type).click()
firefox.find_element_by_xpath('//td[contains(.,"%s")]/following-sibling::td[4]/a[2]'%(goodsClassName)).click()
time.sleep(10)
# 4.将"商品分类测试"的分类排序修改为4,点击保存分类按钮
firefox.find_element_by_id("class_sort").clear()
firefox.find_element_by_id("class_sort").send_keys(4)
firefox.find_element_by_xpath('//button[2]').click()
time.sleep(15)
s = firefox.find_element_by_xpath\
    ('//td[contains(.,"%s")]/following-sibling::td[2]/input'%(goodsClassName)).get_property("value")
print(s)
# 断言
if s == "4":
    writeLog("%s 测试通过" % testcase)
else:
    writeLog("%s 测试失败" % testcase)
    getPhoto(firefox)
# firefox.quit()